package com.czmh.etc.onlinepubsys.utils.mingchuang;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import java.beans.Introspector;
import java.beans.PropertyDescriptor;

public abstract class WxRequestParam2XmlUtil {

    public static String object2XmlString(Object param) throws Exception {
        Document doc = DocumentHelper.createDocument();
        Element root = doc.addElement("xml");
        PropertyDescriptor[] pds = Introspector.getBeanInfo(param.getClass(), Object.class)
                .getPropertyDescriptors();
        for (PropertyDescriptor pd : pds) {
            root.addElement(pd.getName()).addText(pd.getReadMethod().invoke(param).toString());
        }
        return doc.asXML();
    }
}
